package itsm.isperp.module.controller;

import itsm.isperp.framework.core.context.ContextHolder;

import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserCache;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 系统控制器（初次进入系统）
 * 
 * @author lizx
 * @date 2013-1-7
 * @version V1.0
 */
@Controller
@RequestMapping("system")
public class SystemController {

	@RequestMapping(value = "errorInfo")
	public ModelAndView errorInfo(String msg) {
		// 如果id为空则加载顶级菜单及第一个菜单的二及菜单
		ModelAndView mv = new ModelAndView("system/errorInfo");
		mv.addObject("msg", msg);
		return mv;

	}

	@RequestMapping(value = "sessionView")
	public ModelAndView sessionInfo(String msg) {
		// 如果id为空则加载顶级菜单及第一个菜单的二及菜单
		ModelAndView mv = new ModelAndView("system/sessionView");

		SecurityContext sc = SecurityContextHolder.getContext();

		ProviderManager authenticationManager = ContextHolder
				.getSpringBean("isperp.authenticationManager");
		DaoAuthenticationProvider dp = (DaoAuthenticationProvider) authenticationManager
				.getProviders().get(0);
		UserCache uc = dp.getUserCache();
		UserDetails ud = uc.getUserFromCache("admin");

		mv.addObject("msg", msg);

		return mv;

	}

}
